package com.example.monitor.web;


import com.example.monitor.model.*;
import com.example.monitor.utils.ServerUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/monitor")
public class MonitorController {


    /**
     * 获取cpu信息
     */
    @GetMapping("/cpu-info")
    public ResponseEntity<CpuEntity> getCpuInfo() {
        CpuEntity cpuInfo = ServerUtil.getCpuInfo();
        return ResponseEntity.ok(cpuInfo);
    }

    /**
     * 获取内存信息
     */
    @GetMapping("/mem-info")
    public ResponseEntity<MemEntity> getMemInfo() {
        MemEntity memInfo = ServerUtil.getMemInfo();
        return ResponseEntity.ok(memInfo);
    }

    /**
     * 获取JVM信息
     */
    @GetMapping("/jvm-info")
    public ResponseEntity<JvmEntity> getJvmInfo() {
        JvmEntity jvmInfo = ServerUtil.getJvmInfo();
        return ResponseEntity.ok(jvmInfo);
    }

    /**
     * 获取系统信息
     */
    @GetMapping("/sys-info")
    public ResponseEntity<SysEntity> getSysInfo() {
        SysEntity sysInfo = ServerUtil.getSysInfo();
        return ResponseEntity.ok(sysInfo);
    }

    /**
     * 获取文件系统信息
     */
    @GetMapping("/sys-file-info")
    public ResponseEntity<List<SysFileEntity>> getSysFileInfo() {
        List<SysFileEntity> sysFileInfo = ServerUtil.getSysFileInfo();
        return ResponseEntity.ok(sysFileInfo);
    }

    /**
     * 获取所有监控信息
     */
    @GetMapping("/all-info")
    public ResponseEntity<Map<String, Object>> getSystemInfo() {
        //6.获取所有系统信息
        Map<String, Object> allInfo = ServerUtil.getAllInfo();

        //8.返回结果
        return ResponseEntity.ok(allInfo);
    }

}
